package javax.core.common.encrypt;

import javax.core.common.utils.StringUtils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * MD5信息加密类
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2021/8/31 21:12
 */
public class MD5MessageEncrypt extends MessageEncrypt {

    @Override
    public byte[] decode(byte[] input) {
        throw new UnsupportedOperationException();
    }

    @Override
    public byte[] encode(byte[] input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(input);
            return StringUtils.bytes2Hex(md.digest()).getBytes();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return new byte[0];
    }
}
